from django.db import models
# AbstractUser继承类，用来重新定义用户注册需要的User类的字段,
# UserManager用来改写在使用createsuperuser的时候，默认是用户名，邮箱，改成用户名，手机号
from django.contrib.auth.models import AbstractUser, UserManager as _UserManager


# Create your models here.


class UserManager(_UserManager):
    def create_superuser(self, username, password, email=None, **extra_fields):
        return super().create_superuser(username=username, password=password, email=email, **extra_fields)


class User(AbstractUser):
    mobile = models.CharField("手机号", max_length=11, unique=True, help_text="手机号",
                              error_messages={"unique": "手机号已注册"})
    email_active = models.BooleanField("邮箱状态", default=False)

    class Meta:
        db_table = "tb_user"    # 定义表名
        verbose_name = "用户"    # 管理后台显示的名称
        verbose_name_plural = verbose_name      # 定义复数时的名称

    def __str__(self):      # 调用时返回自身的属性，不然都是显示xx  project
        return self.username

    objects = UserManager()
    REQUIRED_FIELDS = ['mobile']    # 修改在createsuperuser时显示的信息，把email换成mobile

























